<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML5 音频示例</title>
</head>

<body>
    <h2>HTML5 音频示例</h1>
        <audio controls preload="auto">
            <source src="https://www.runoob.com/try/demo_source/horse.mp3" type="audio/mpeg">
            <source src="https://www.runoob.com/try/demo_source/horse.ogg" type="audio/mpeg">
            您的浏览器不支持音频标签。
        </audio>
        <script>
            window.onload = () => {
                // 设置音量为50%
                const audio = document.querySelector('audio');
                audio.volume = 0.5;
                // 监听播放完毕
                audio.addEventListener('ended', () => {
                    console.log('音频播放完毕');
                });
            }
        </script>
</body>

</html>